package com.hair.grpc.example.service;

import com.github.examples.grpc.lib.HelloReply;
import com.github.examples.grpc.lib.HelloRequest;
import com.github.examples.grpc.lib.SimpleGrpc;
import com.github.grpc.client.annotation.GrpcClient;
import io.grpc.Channel;
import org.springframework.stereotype.Service;


@Service
public class HelloService {

    @GrpcClient
    private Channel channel;


    public String sendMessage(String name) {
        SimpleGrpc.SimpleBlockingStub stub = SimpleGrpc.newBlockingStub(channel);
        HelloRequest helloRequest = HelloRequest.newBuilder().setName(name).build();
        HelloReply helloReply = stub.sayHello(helloRequest);
        return helloReply.getMessage();
    }
}
